# -*- coding: utf-8 -*-
# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
from __future__ import annotations

from typing import MutableMapping, MutableSequence

from google.type import expr_pb2  # type: ignore
import proto  # type: ignore

__protobuf__ = proto.module(
    package="google.cloud.securitycenter.v1",
    manifest={
        "CustomConfig",
    },
)


class CustomConfig(proto.Message):
    r"""Defines the properties in a custom module configuration for
    Security Health Analytics. Use the custom module configuration
    to create custom detectors that generate custom findings for
    resources that you specify.

    Attributes:
        predicate (google.type.expr_pb2.Expr):
            The CEL expression to evaluate to produce
            findings. When the expression evaluates to true
            against a resource, a finding is generated.
        custom_output (google.cloud.securitycenter_v1.types.CustomConfig.CustomOutputSpec):
            Custom output properties.
        resource_selector (google.cloud.securitycenter_v1.types.CustomConfig.ResourceSelector):
            The resource types that the custom module
            operates on. Each custom module can specify up
            to 5 resource types.
        severity (google.cloud.securitycenter_v1.types.CustomConfig.Severity):
            The severity to assign to findings generated
            by the module.
        description (str):
            Text that describes the vulnerability or
            misconfiguration that the custom module detects.
            This explanation is returned with each finding
            instance to help investigators understand the
            detected issue. The text must be enclosed in
            quotation marks.
        recommendation (str):
            An explanation of the recommended steps that security teams
            can take to resolve the detected issue. This explanation is
            returned with each finding generated by this module in the
            ``nextSteps`` property of the finding JSON.
    """

    class Severity(proto.Enum):
        r"""Defines the valid value options for the severity of a
        finding.

        Values:
            SEVERITY_UNSPECIFIED (0):
                Unspecified severity.
            CRITICAL (1):
                Critical severity.
            HIGH (2):
                High severity.
            MEDIUM (3):
                Medium severity.
            LOW (4):
                Low severity.
        """
        SEVERITY_UNSPECIFIED = 0
        CRITICAL = 1
        HIGH = 2
        MEDIUM = 3
        LOW = 4

    class CustomOutputSpec(proto.Message):
        r"""A set of optional name-value pairs that define custom source
        properties to return with each finding that is generated by the
        custom module. The custom source properties that are defined here
        are included in the finding JSON under ``sourceProperties``.

        Attributes:
            properties (MutableSequence[google.cloud.securitycenter_v1.types.CustomConfig.CustomOutputSpec.Property]):
                A list of custom output properties to add to
                the finding.
        """

        class Property(proto.Message):
            r"""An individual name-value pair that defines a custom source
            property.

            Attributes:
                name (str):
                    Name of the property for the custom output.
                value_expression (google.type.expr_pb2.Expr):
                    The CEL expression for the custom output. A
                    resource property can be specified to return the
                    value of the property or a text string enclosed
                    in quotation marks.
            """

            name: str = proto.Field(
                proto.STRING,
                number=1,
            )
            value_expression: expr_pb2.Expr = proto.Field(
                proto.MESSAGE,
                number=2,
                message=expr_pb2.Expr,
            )

        properties: MutableSequence[
            "CustomConfig.CustomOutputSpec.Property"
        ] = proto.RepeatedField(
            proto.MESSAGE,
            number=1,
            message="CustomConfig.CustomOutputSpec.Property",
        )

    class ResourceSelector(proto.Message):
        r"""Resource for selecting resource type.

        Attributes:
            resource_types (MutableSequence[str]):
                The resource types to run the detector on.
        """

        resource_types: MutableSequence[str] = proto.RepeatedField(
            proto.STRING,
            number=1,
        )

    predicate: expr_pb2.Expr = proto.Field(
        proto.MESSAGE,
        number=1,
        message=expr_pb2.Expr,
    )
    custom_output: CustomOutputSpec = proto.Field(
        proto.MESSAGE,
        number=2,
        message=CustomOutputSpec,
    )
    resource_selector: ResourceSelector = proto.Field(
        proto.MESSAGE,
        number=3,
        message=ResourceSelector,
    )
    severity: Severity = proto.Field(
        proto.ENUM,
        number=4,
        enum=Severity,
    )
    description: str = proto.Field(
        proto.STRING,
        number=5,
    )
    recommendation: str = proto.Field(
        proto.STRING,
        number=6,
    )


__all__ = tuple(sorted(__protobuf__.manifest))
